<!--
 作者：ex_wangshuai
 日期：2016-11-02
 功能：首页-知己彼-主页主组件
 参数：
 事件：
-->
<template>
  <div class="slide-menu">
    <div class="opacityDom" @click="hidden"></div>
    <div class="content" transition="expand" v-show="slideState">
      <div class="close text-right">
        <span @click="hidden">&nbsp;</span>
      </div>
      <div class="left-tab">
        <ul class="">
          <li
            @click="changeTab(tabItem.order)"
            v-for="tabItem in tabList"
            track-by="order"
            :class="['flex1 display-flex align-items justify-content', { 'tabActive': activeStyle == $index }]">
            {{tabItem.name}}
          </li>
        </ul>
        <div class="active-bg"></div>
      </div>
      <div class="right-content">
        <div v-for="rightList in contentList" :class="['container', 'showNone', { 'showBlock': $index == activeStyle}]">
          <div v-else class="clearfix">
            <div v-for="contentItems in rightList" class="subBox2">
              <div data-key="{{itemImg.mkey}}" v-for="itemImg in contentItems.childs"
                   :class="['itemImg', { 'activeBackground': routeKey == itemImg.mkey}]"
                   track-by="$index" @click="imgChecked($event)">
                <p class="pageName">{{itemImg.name}}</p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import Toolbar from '../common/Toolbar.vue'

  export default{
    data () {
      var data = {}
      data.viewTitle = '知己彼'
      data.slideState = false
      data.tabList = []
      data.routeKey = ''
      data.activeStyle = 0
      data.contentList = []
      data.isEdit = false
      data.collectedAll = []
      data.mkeyAll = []
      data.page = []
      return data
    },
    components: {
      Toolbar
    },
    events: {
      'slideStart': function () {
        this.slideState = true
      }
    },
    methods: {
      closeMenu: function () {
        this.$parent.menuOpenState = false
      },
      goBack: function () {
        window.history.back()
      },
      editList: function () {
        this.isEdit = !this.isEdit
      },
      hidden: function () {
        this.slideState = false
        var self = this
        setTimeout(function () {
          self.$parent.menuOpenState = false
        }, 200)
      },
      // 点击tab触发
      changeTab: function (order) {
        document.querySelector('.active-bg').style.top = (order * 1 + 1) + 'rem'
        this.activeStyle = order
      },
      // 点击跳转路由
      imgChecked: function (event) {
        var boxChecked = event.target.parentNode
        var clickKey = boxChecked.getAttribute('data-key')
        boxChecked.style.background = 'rgba(74,144,226,.3)'
        this.$route.router.go('/peer/' + clickKey + '?key=' + clickKey)
        this.$parent.menuOpenState = false
      }
    },
    ready: function () {
      this.routeKey = this.$parent.routeKey
      var leftNumber = 0
      for (var j = 0; j < this.mkeyAll.length; j++) {
        if (this.mkeyAll[j] === this.routeKey) {
          leftNumber = j + 1
        }
      }

      var number = 0
      var activeStyle = 0
      for (var k = 0; k < this.page.length; k++) {
        number += this.page[k]
        if (number >= leftNumber) {
          activeStyle = k
          break
        }
      }

      if (this.routeKey && this.routeKey.indexOf('product') > -1) {
        number = 1
        activeStyle = 1
      }

      document.querySelector('.active-bg').style.top = (activeStyle * 1 + 1) + 'rem'
      this.activeStyle = activeStyle
    },
    created () {
      var tabList = JSON.parse(window.sessionStorage.getItem('peerTabList'))
      var contentList = JSON.parse(window.sessionStorage.getItem('peerContentList'))
      var mkeyAll = JSON.parse(window.sessionStorage.getItem('peerMkeyAll'))
      var number1 = 0
      var page = []
      for (var i = 0; i < contentList.length; i++) {
        if (i !== 0) {
          page.push(contentList[i].length)
        }
      }
      number1 = mkeyAll.length
      page.unshift(number1)
      this.page = page
      this.mkeyAll = mkeyAll
      this.tabList = tabList
      this.contentList = contentList
    }
  }
</script>

<style lang="scss" scoped>
  .slide-menu{
    width: 7.5rem;
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 1010;
  }
  .opacityDom{
    position: absolute;
    left: 0;
    top: 0;
    background: rgba(0,0,0,.3);
    width: 100%;
    height: 100%;
    z-index: 1011;
  }
  .content {
    position: absolute;
    top: 0vh;
    right: 0;
    width: 80%;
    height: 100%;
    overflow: hidden;
    background: #FFF;
    z-index: 1012;

  }
  .close{
    position: absolute;
    display: block;
    top: .3rem;
    right: .3rem;
    width: .3rem;
    height: .3rem;
    background: url("") no-repeat center center / 100% 100%;
  }

  /*左边tab*/
  div.left-tab {
    position: relative;
    float: left;
    padding-top: 1rem;
    width: 30%;
    height: 100%;
    box-sizing: border-box;
    box-shadow: #dddddd 2px 2px 5px;

  .active-bg {
    position: absolute;
    left: 0;
    top: 1rem;
    width: 100%;
    height: 1rem;
    background: url("") no-repeat center top;
    background-size: 100% 100%;
    transition: all .2s;
    z-index: 0;
  }

  ul {
    position: relative;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    flex-direction: column;
    z-index: 1;
  li {
    height: 1rem;
    font-size: .32rem;
    color: #999999;

  &:last-child {
     border-bottom: none;
   }
  }
  .tabActive {
    position: relative;
    /*background: #4A90E2;*/
    color: #ffffff;
    border-right: none;
  }
  .tabActive:after {
    content: '';
    position: absolute;
    right: 0;
    top: 42%;
    border: 0.1rem solid #000;
    border-color: transparent #ffffff transparent transparent;
  }
  }
  }

  /*右边内容*/
  div.right-content {
    float: left;
    padding-top: 1rem;
    width: 70%;
    height: 100%;
    box-sizing: border-box;



  div.subBox2 {
    width: 100%;
    float: left;

  div.itemImg {
    position: relative;
    width: 100%;

  img {
    height: 1.6rem;
    display: block;
    margin: auto;
  }
  p.pageName {
    font-size: 0.26rem;
    color: #999999;
    padding: 0.34rem 0 0.34rem 0.55rem;
    background: url("") no-repeat 88% 49% / .15rem .23rem;
  }
  }
  }
  }

  .checked:after {
    content: "\221A";
    position: absolute;
    display: block;
    background: #4A90E2;
    border-radius: 50%;
    width: .48rem;
    height: .48rem;
    right: 6%;
    bottom: 39%;
    text-align: center;
    color: #ffffff;
    line-height: 0.48rem;
  }

  .imgNoC img {
    -webkit-filter: grayscale(1)
  }
  .container{
    height: 100%;
    overflow: auto;
  }
  .subTitle{
    color: #000;
    padding-left: 0.2rem;
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
  }
  .activeBackground{
    background: rgba(188, 219, 255, 0.4);
  }
  .showNone{
    display: none;
  }
  .showBlock{
    display: block !important;
  }
</style>
